<?php

namespace App\Admin\Controllers;

use App\Models\GoldSubsidy;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Controllers\AdminController;

class GoldSubsidiesController extends AdminController
{
    protected $title = '金店补贴金';

    protected function grid()
    {
        $grid = new Grid(new GoldSubsidy());
        $grid->model()->orderByDesc('id');

        if ($userId = request('user_id')) {
            $grid->model()->where('user_id', $userId)->orderByDesc('id');
        }

        $grid->column('id', 'ID');
        $grid->column('user', '会员')->display(function () {
            return $this->user->nameText(true);
        });
        $grid->column('money', '金额');
        $grid->column('origin', '原额');
        $grid->column('result', '现额');
        $grid->column('reason', '事由');
        $grid->column('created_at', '时间')->display(function () {
            return (string)$this->created_at;
        });

        $this->gridFilter($grid);

        $grid->disableRowSelector();
        $grid->disableCreateButton();
        $grid->disableExport();
        $grid->disableActions();

        return $grid;
    }

    protected function gridFilter(Grid $grid)
    {
        $grid->filter(function (Grid\Filter $filter) {
            $filter->expand();
            $filter->column(1/2, function (Grid\Filter $filter) {
                $filter->disableIdFilter();
                $filter->equal('user_id', '会员 ID 查询');
            });
        });
    }

}
